R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'tidyr' was built under R version 4.3.3
## Warning: package 'readr' was built under R version 4.3.3
## Warning: package 'purrr' was built under R version 4.3.3
## Warning: package 'dplyr' was built under R version 4.3.3
## Warning: package 'stringr' was built under R version 4.3.3
## Warning: package 'forcats' was built under R version 4.3.3
## Warning: package 'lubridate' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(readxl)
library(dplyr)
invoice_data<-read_excel("D:/B.tech 2nd(Sem 4)/Excel Dashboard/supermarket_sales - Sheet1.xlsx")
View(invoice_data)
str(invoice_data)
## tibble [1,000 × 17] (S3: tbl_df/tbl/data.frame)
##  $ Invoice ID             : chr [1:1000] "750-67-8428" "226-31-3081" "631-41-3108" "123-19-1176" ...
##  $ Branch                 : chr [1:1000] "A" "C" "A" "A" ...
##  $ City                   : chr [1:1000] "Yangon" "Naypyitaw" "Yangon" "Yangon" ...
##  $ Customer_type          : chr [1:1000] "Member" "Normal" "Normal" "Member" ...
##  $ Gender                 : chr [1:1000] "Female" "Female" "Male" "Male" ...
##  $ Product_Line           : chr [1:1000] "Health and beauty" "Electronic accessories" "Home and lifestyle" "Health and beauty" ...
##  $ Unit price             : num [1:1000] 74.7 15.3 46.3 58.2 86.3 ...
##  $ Quantity               : num [1:1000] 7 5 7 8 7 7 6 10 2 3 ...
##  $ Tax 5%                 : num [1:1000] 26.14 3.82 16.22 23.29 30.21 ...
##  $ Total                  : num [1:1000] 549 80.2 340.5 489 634.4 ...
##  $ Date                   : chr [1:1000] "43586" "43680" "43527" "1/27/2019" ...
##  $ Time                   : POSIXct[1:1000], format: "1899-12-31 13:08:00" "1899-12-31 10:29:00" ...
##  $ Payment                : chr [1:1000] "Ewallet" "Cash" "Credit card" "Ewallet" ...
##  $ cogs                   : num [1:1000] 522.8 76.4 324.3 465.8 604.2 ...
##  $ gross margin percentage: num [1:1000] 4.76 4.76 4.76 4.76 4.76 ...
##  $ gross income           : num [1:1000] 26.14 3.82 16.22 23.29 30.21 ...
##  $ Rating                 : num [1:1000] 9.1 9.6 7.4 8.4 5.3 4.1 5.8 8 7.2 5.9 ...

Including Plots

You can also embed plots, for example:

# Calculate total sales by branch
sales_by_branch <- invoice_data %>%
  group_by(Branch) %>%
  summarise(Total_Sales = sum(Total))

# Create a bar chart for sales by branch
ggplot(sales_by_branch, aes(x = Branch, y = Total_Sales, fill = Branch)) +
  geom_bar(stat = "identity") +
  labs(title = "Total Sales by Branch", x = "Branch", y = "Total Sales") +
  theme_minimal()

sales_by_product <- invoice_data %>%
  group_by(Product_Line) %>%
  summarise(Total_Sales = sum(Total))

# Create a horizontal bar chart for product line performance
ggplot(sales_by_product, aes(x = Total_Sales, y = Product_Line, fill = Product_Line)) +
  geom_bar(stat = "identity") +
  labs(title = "Product Line Performance", x = "Total Sales", y = "Product Line")+
  theme_minimal() +
  coord_flip()

sales_by_payment <- invoice_data %>%
  group_by(Payment) %>%
  summarise(Total_Sales = sum(Total))

# Create a pie chart for payment method analysis using Plotly
pie_chart <- plot_ly(sales_by_payment, labels = ~Payment, values = ~Total_Sales, type = "pie",textinfo = "percent+label", hoverinfo = "label+value") %>%
  layout(title = "Payment Method Analysis")
pie_chart  # Display the interactive pie chart (plotly)
# Create a box plot to visualize sales distribution by product category
ggplot(invoice_data, aes(x = Product_Line, y = Total)) +
  geom_boxplot() +
  labs(title = "Sales Distribution by Product Category", x = "Product Category", y = "Sales") +
  theme_minimal()

# Create a scatter plot to explore the relationship between sales and quantity
ggplot(invoice_data, aes(x = Quantity, y = Total)) +
  geom_point() +
  labs(title = "Sales vs. Quantity", x = "Quantity", y = "Sales") +
  theme_minimal()

ggplot(invoice_data, aes(x= Total,y=Branch, group = City, color = City)) +
  geom_line() +
  geom_point()+
  labs(title = "City-Wise Sales Amount",
       x = "Sales Amount",
       y="Branch") +
  theme_minimal()

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.